import debounce from 'lodash.debounce'

var pageNum = 10;

export default function addScroll(that) {
	var distanceNum = 40; //距离底部还有多少开始加载数据
	var obj = that.$refs.scroll;
	var dH = that.$refs.dH;
	var wH = document.documentElement.offsetHeight;

	obj.addEventListener('scroll', debounce(function (e) {
		var docH = dH.offsetHeight
		var sY = obj.scrollTop;

		if(wH + sY + distanceNum >= docH){
			sendAjax(that)
		}
	}, 200))
}

//滚动到底部， 开始加载更多数据
function sendAjax(that){
	//判断是否需要发送请求（是否已加载完所有数据）
	console.log(that.page * pageNum, that.total)
	if(that.page * pageNum >= that.total) return;

	that.topNav()
	console.log('到底了')
}
